<%@ page contentType="text/html;charset=utf-8"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<%@ page import="java.io.*,control.database.*"%>
<HTML><HEAD><TITLE>灵通邮件统计页面</TITLE>

<LINK href="Default.files/css.css" type=text/css rel=stylesheet>

<SCRIPT src="fPopUpCalendarDlg.js"></SCRIPT>
<% 
String section="0";
 section=(String)session.getAttribute("mger_code");
%>
<SCRIPT language=javascript>
function check(){

	option.submit();
	return true;
	}
	



</SCRIPT>
</HEAD>
<BODY >

<%
 String monthtime="";
 String username_type="10";
String nowtime=new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
  if((request.getParameter("year")!=null)&(request.getParameter("month")!=null)){
    monthtime=request.getParameter("year")+request.getParameter("month");
    if((request.getParameter("year").equals("1000"))||(request.getParameter("month").equals("1000"))){
    monthtime=new SimpleDateFormat("yyyyMM").format(new Date());
    }
    }
    else{
    monthtime=new SimpleDateFormat("yyyyMM").format(new Date());
    }
  if((request.getParameter("areacode")!=null))
  {
  section=request.getParameter("areacode");
  }
  String grade=request.getParameter("grade");
  if(request.getParameter("user_type")!=null){
  username_type=request.getParameter("user_type").trim();
  }
  String count="";
  %>
  


<FORM name=option action="download.jsp" method=post> 
   
<TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
    <TD vAlign=top align="center" colSpan=2>
							<TABLE cellSpacing=0 cellPadding=0 width="100%" bgColor=#f1f1f1 border=0>
								<TBODY>
									<TR height=40>
										<TD>
											<FONT color="#00ff80">
												<FONT color="#8000ff">
													 灵通传真邮箱用户导出
												</FONT>
											</FONT>
										</TD>
										
										<TD align=left>
		 <%if(((String)session.getAttribute("mger_code")).equals("0")){%>
		 
		 <select name="areacode" size=1>
             <%
                DataBase db=new DataBase();
          		ResultSet rst=db.executeQuery("select * from mz_areacode where areaid=1 order by sortid");
          		while(rst.next()){
          %>
            <option value="<%=rst.getString("areacode")%>" <%if(section.equals(rst.getString("areacode")))out.print("selected");%>><%out.print(rst.getString("areaname"));%> </option>
            <%}
            rst.close();
            db.closeStmt();
	    	db.closeConn();
            
            %></select>
            <%}%>
            <TD align=middle>会员类型</TD>
          <TD align=left><select name="user_type" class=9pt style="WIDTH: 70px">
                    <option value='10' <%if((request.getParameter("user_type")!=null)&&(request.getParameter("user_type").equals("10")))out.print("selected");%>><%out.print("(全部)");%></option>
                    <option value='PHS' <%if((request.getParameter("user_type")!=null)&&(request.getParameter("user_type").equals("PHS")))out.print("selected");%>><%out.print("小灵通");%></option>
                    <option value='PSTN' <%if((request.getParameter("user_type")!=null)&&(request.getParameter("user_type").equals("PSTN")))out.print("selected");%>><%out.print("固话");%></option>
                    <!-- option value='NET' <%if((request.getParameter("user_type")!=null)&&(request.getParameter("user_type").equals("NET")))out.print("selected");%>><%out.print("宽带");%></option-->
                    </select>
          </TD>
            <td>业务类型
            <select name="grade" class=9pt style="WIDTH: 70px">
            <option value='10' <%if((request.getParameter("grade")!=null)&&(request.getParameter("grade").equals("10")))out.print("selected");%>><%out.print("(全部)");%></option>
                    
                    <option value='1' <%if((request.getParameter("grade")!=null)&&(request.getParameter("grade").equals("1")))out.print("selected");%>><%out.print("普通");%></option>
                    <option value='2' <%if((request.getParameter("grade")!=null)&&(request.getParameter("grade").equals("2")))out.print("selected");%>><%out.print("商务");%></option>
                    <option value='3' <%if((request.getParameter("grade")!=null)&&(request.getParameter("grade").equals("3")))out.print("selected");%>><%out.print("精英");%></option>
                    <option value='8' <%if((request.getParameter("grade")!=null)&&(request.getParameter("grade").equals("8")))out.print("selected");%>><%out.print("特惠");%></option>
            
          
            </select>
            </td><td>
            时间范围<select name="year" size=1>
         <option value="1000" selected><%out.print("无时间限制");%> </option>
         <option value="2006" <%if(monthtime.indexOf("2006")!=-1)out.print("selected");%>><%out.print("2006年");%> </option>
           <option value="2007" <%if(monthtime.indexOf("2007")!=-1)out.print("selected");%>><%out.print("2007年");%> </option>
            <option value="2008" <%if(monthtime.indexOf("2008")!=-1)out.print("selected");%>><%out.print("2008年");%> </option>
            <option value="2009" <%if(monthtime.indexOf("2009")!=-1)out.print("selected");%>><%out.print("2009年");%> </option>
            <option value="2010" <%if(monthtime.indexOf("2010")!=-1)out.print("selected");%>><%out.print("2010年");%> </option>
            <option value="2011" <%if(monthtime.indexOf("2011")!=-1)out.print("selected");%>><%out.print("2011年");%> </option>
            <option value="2012" <%if(monthtime.indexOf("2012")!=-1)out.print("selected");%>><%out.print("2012年");%> </option>
            <option value="2013" <%if(monthtime.indexOf("2013")!=-1)out.print("selected");%>><%out.print("2013年");%> </option>
            <option value="2014" <%if(monthtime.indexOf("2014")!=-1)out.print("selected");%>><%out.print("2014年");%> </option>
            <option value="2015" <%if(monthtime.indexOf("2015")!=-1)out.print("selected");%>><%out.print("2015年");%> </option>
            <option value="2016" <%if(monthtime.indexOf("2016")!=-1)out.print("selected");%>><%out.print("2016年");%> </option>
            <option value="2017" <%if(monthtime.indexOf("2017")!=-1)out.print("selected");%>><%out.print("2017年");%> </option>
            </select><select name="month" size=1>
         <option value="1000" selected><%out.print("无时间限制");%> </option>
             <option value="01" <%if(monthtime.substring(4,6).indexOf("01")!=-1)out.print("selected");%>><%out.print("一月");%> </option>
            <option value="02" <%if(monthtime.substring(4,6).indexOf("02")!=-1)out.print("selected");%>><%out.print("二月");%> </option>
            <option value="03" <%if(monthtime.substring(4,6).indexOf("03")!=-1)out.print("selected");%>><%out.print("三月");%> </option>
            <option value="04" <%if(monthtime.substring(4,6).indexOf("04")!=-1)out.print("selected");%>><%out.print("四月");%> </option>
            <option value="05" <%if(monthtime.substring(4,6).indexOf("05")!=-1)out.print("selected");%>><%out.print("五月");%> </option>
            <option value="06" <%if(monthtime.substring(4,6).indexOf("06")!=-1)out.print("selected");%>><%out.print("六月");%> </option>
            <option value="07" <%if(monthtime.substring(4,6).indexOf("07")!=-1)out.print("selected");%>><%out.print("七月");%> </option>
            <option value="08" <%if(monthtime.substring(4,6).indexOf("08")!=-1)out.print("selected");%>><%out.print("八月");%> </option>
            <option value="09" <%if(monthtime.substring(4,6).indexOf("09")!=-1)out.print("selected");%>><%out.print("九月");%> </option>
            <option value="10" <%if(monthtime.substring(4,6).indexOf("10")!=-1)out.print("selected");%>><%out.print("十月");%> </option>
            <option value="11" <%if(monthtime.substring(4,6).indexOf("11")!=-1)out.print("selected");%>><%out.print("十一月");%> </option>
            <option value="12" <%if(monthtime.substring(4,6).indexOf("12")!=-1)out.print("selected");%>><%out.print("十二月");%> </option>
          
            </select></td><td><INPUT type=button name=tongji value="提交" onclick="return check()"></TD>
          
									</TR>
								</TBODY>
							</TABLE>
							<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
								<TBODY>
									<TR>
										<TD>
											<TABLE id=dgDownLoad style="BORDER-LEFT-COLOR: #cccccc; BORDER-BOTTOM-COLOR: #cccccc; WIDTH: 100%; BORDER-TOP-COLOR: #cccccc; BORDER-COLLAPSE: collapse; BORDER-RIGHT-COLOR: #cccccc" borderColor=#cccccc cellSpacing=0 rules=all border=1>
												<TBODY>
														<TR style="BACKGROUND-COLOR: #d0ebee" align="center">
													    <TD style="WIDTH: 5%">
															<FONT color="#ff0080">&nbsp;</FONT>
														</TD>
	
													</TR>
													<TR><TD><FONT color="#8080ff">
												<%
											if(request.getParameter("today")==null){
												   String sql="select * from users where domainName='10060.com' and username like '"+section+"%' and lastLoginDate like '"+monthtime+"%'";
												   String sql_count="select count(*)as num from users where domainName='10060.com' and username like '"+section+"%' and lastLoginDate like '"+monthtime+"%'";	   
												   if(!grade.equals("10")){
												   try{
												   sql+="and grade="+Integer.parseInt(grade);
												   sql_count+="and grade="+Integer.parseInt(grade);
												   
												   }catch(Exception e){
												   sql+="and grade=1";
												   sql_count+="and grade=1";
												   }
												   }
												     if(!username_type.equals("10")){
												   try{
												   sql+=" and user_type='"+username_type+"'";
												   sql_count+=" and user_type='"+username_type+"'";
												   
												   }catch(Exception e){
												   
												   }
												   }
												    Context initCtx = new InitialContext();
												    Context envCtx = (Context) initCtx.lookup("java:comp/env");
												    DataSource ds = (DataSource) envCtx.lookup("jdbc/TestDB");  
												    Connection conn = ds.getConnection();
												    Statement stmt = conn.createStatement();
													ResultSet rst = stmt.executeQuery(sql_count);
													while(rst.next()){
													count=rst.getString("num");
													//out.println(rst.getString("num"));
													}
													rst = stmt.executeQuery(sql);
													//File f=new File("user/"+section+"_code.txt");
													FileWriter output = new FileWriter("D://Program Files/Apache Software Foundation/Tomcat 5.5/webapps/cncChina/customer/sp.files/user/"+nowtime+"_"+section+"code.txt");
													BufferedWriter bw = new BufferedWriter(output);
													while(rst.next()){
														   try{
															bw.write(rst.getString("username")+","+rst.getString("grade"));
															bw.newLine();
														   }catch(Exception e){
															  
														   }
														}
															bw.close();
												rst.close();
												stmt.close();
												conn.close();
												
								              if(section.equals("024"))out.println("沈阳分公司");
								              else if(section.equals("0"))out.println("辽宁省公司");
											  else if(section.equals("0410"))out.println("铁岭分公司");
											  else if(section.equals("0411"))out.println("大连分公司");
											  else if(section.equals("0412"))out.println("鞍山分公司");
											  else if(section.equals("0413"))out.println("抚顺分公司");
											  else if(section.equals("0414"))out.println("本溪分公司");
											  else if(section.equals("0415"))out.println("丹东分公司");
											  else if(section.equals("0416"))out.println("锦州分公司");
											  else if(section.equals("0417"))out.println("营口分公司");
											  else if(section.equals("0418"))out.println("阜新分公司");
											  else if(section.equals("0419"))out.println("辽阳分公司");
											  else if(section.equals("0421"))out.println("朝阳分公司");
											  else if(section.equals("0427"))out.println("盘锦分公司");
											  else if(section.equals("0429"))out.println("葫芦岛公司");
			                                  
												%>的用户总数为<%=count%><a href="do_download.jsp?section=<%=(nowtime+"_"+section)%>">导出符合条件的号码</a>
												
													<%}
												%></FONT></TD></TR>

												</TBODY>
											</TABLE>
										</TD>
									</TR>
								</TBODY>
							</TABLE>
						</TD></TR>
  <TR>
    <TD height=20>
      <TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
        <TBODY>
        <TR>
          <!-- TD width=180><IMG height=40 
            src="Default.files/main_bottom_pic01.gif" width=180></TD-->
          <TD width="40%" background=Default.files/main_bottom_bg.gif></TD>
          <TD align=right background=Default.files/main_bottom_bg.gif>
            </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></FORM></BODY></HTML>
